import designEditor from "@/editorComponent/designEditor";
import editorStore from "@/editorComponent/editorStore";
import clsx from "clsx";
import { autorun } from "mobx";
import { useEffect, useRef, useState } from "react";
import styles from "./toolRendering.module.less";

// 渲染按钮
export default function ToolRendering() {

  const dom = useRef<HTMLDivElement | null>(null);
  const [hover, setHover] = useState(false);
  const [visible, setVisible] = useState(false);
  const [disable, setDisable] = useState(false);

  useEffect(() => autorun(() => {
    const { activeObjectId, lock } = editorStore;
    setDisable(lock);

    const activeObject = designEditor.fabricCanvas.getActiveObject();
    if (activeObjectId && activeObject && activeObject.type === "image") {
      setVisible(true);
    } else {
      setVisible(false);
    }
  }), []);

  return (
    <div
      ref={dom}
      className={clsx(styles.toolRendering, visible && styles.visible, disable && styles.disable, hover && styles.hover)}
    >
      渲染
    </div>
  );

}
